<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
    <div id="app">
        <ul>
            <li v-for="item in Arr">{{item}}</li>
        </ul>
        <ul>
            <li v-for="(item,index) in Arr">{{index+1}}{{item}}</li>
        </ul>
        <ul>
            <li v-for="(item,index) in Obj">{{item.name}}</li>
        </ul>
        <button @click="add">添加</button>
        <button @click="remove">删除</button>
    </div>
    <!-- 1.v-for指令的作用是：根据数据生成列表结构
    2.数组经常和v-for结合使用
    3.语法是(item,index) in 数据
    4.item和index可以结合其他指令一起使用
    5.数组长度的更新会同步到页面上，是响应式的 -->
    <script>
        var app = new Vue({
            el:'#app',
            data:{
                Arr:["北京","上海","哈尔滨"],
                Obj:[{name:'鱼香肉丝'},{name:'鱼香肉丝222'}]
            },
            methods:{
                add:function(){
                    this.Obj.push({name:'水煮肉片'});
                },
                remove:function(){
                    this.Obj.shift();
                }
            }
        })
    </script>
</body>
</html>